<template>
	<view>
		<view class="search_box">
			<input v-model="form.title" type="text" placeholder="请输入关键词" class="input-box" @confirm="onConfirm" />
			<view class="">
				<scroll-view class="scroll-view_H" scroll-x="true">
					<view :class="form.tid==0?'scroll-view-item_H active':'scroll-view-item_H'"
						@click="editcate(0)">全部</view>
					<view :class="form.tid==item.id?'scroll-view-item_H active':'scroll-view-item_H'"
						v-for="(item,index) in cateList" :key="index" @click="editcate(item.id)">
						{{item.tname}}
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="cart_list">
			<view class="cart_item" v-for="(item,index) in list" :key="index" @click="go_detail(item)">
				<view class="cart_image">
					<image :src="item.pic" mode="aspectFill"></image>
					<view class="time">
						有效期至:{{item.show_day}}
					</view>
				</view>
				<view class="title">
					{{item.title}}
				</view>
			</view>
		</view>
		<view class="d-c-c p30" v-if="list.length == 0">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					page: 1,
					list_row: 20,
					tid: 0,
					title: '',
				},
				cateList: [],
				list: [],
				last_page: 0,
			}
		},
		onLoad() {
			this.getcate()
			this.list = []
			this.form.page = 1
			this.getData()
		},
		onReachBottom() {
			if (this.form.page < this.last_page) {
				this.form.page++
				this.getData()
			}
		},
		methods: {
			editcate(e) {
				this.form.tid = e
				this.list = []
				this.form.page = 1
				this.getData()
			},
			onConfirm() {
				this.list = []
				this.form.page = 1
				this.getData()
			},
			getcate() {
				let self = this
				self._post('user.user/plug_type', {}, function(res) {
					self.cateList = res.data
				});
			},
			getData() {
				let self = this
				let params = self.form
				self._post('user.user/plugs', params, function(res) {
					self.list = self.list.concat(res.data.data)
					self.last_page = res.data.last_page
				});
			},
			go_detail(item) {
				uni.navigateToMiniProgram({
					appId: item.wx_appid,
					path: item.wx_url,
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	.cart_list {
		display: flex;
		flex-wrap: wrap;
		width: 700rpx;
		margin: 0 auto;

		.cart_item {
			background-color: #fff;
			margin: 10rpx;
			width: 330rpx;

			.cart_image {
				width: 330rpx;
				height: 200rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}

				.time {
					position: absolute;
					left: 0;
					right: 0;
					bottom: 0;
					z-index: 9;
					width: 100%;
					height: 50rpx;
					line-height: 50rpx;
					background-color: rgba(0, 0, 0, .5);
					color: #fff;
					font-size: 22rpx;
					text-align: center;
				}
			}

			.title {
				margin: 20rpx;
				overflow: hidden;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				text-overflow: ellipsis;
				white-space: normal;
				height: 64rpx;
				;
			}
		}


	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
		margin-top: 20rpx;

		.scroll-view-item_H {
			display: inline-block;
			padding: 0 20rpx;
			height: 88rpx;
			line-height: 88rpx;
			font-size: 28rpx;
			color: #333;
		}

		.active {
			color: #1bae61;
			font-weight: bold;
			position: relative;

			&::after {
				position: absolute;
				left: 0;
				right: 0;
				bottom: 10rpx;
				content: '';
				width: 30rpx;
				height: 4rpx;
				background-color: #1bae61;
				margin: 0 auto;
			}
		}
	}

	.search_box {
		width: 100%;
		background-color: #fff;
		padding: 20rpx;
		box-sizing: border-box;

		.input-box {
			width: 686rpx;
			height: 80rpx;
			line-height: 80rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			background-color: #f8f8f8;
			font-size: 28rpx;
			margin: 0 auto;
			border-radius: 40rpx;
		}
	}
</style>